package com.ljkj.blockpay.ui.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.kongzue.baseokhttp.util.JsonList;
import com.ljkj.blockpay.R;
import com.ljkj.blockpay.basedata.BaseActivity;
import com.ljkj.blockpay.databinding.ActivitySelectBinding;
import com.ljkj.blockpay.model.CommonModel;
import com.ljkj.blockpay.presenter.SelectPresenter;
import com.ljkj.blockpay.presenter.inter.SelectInter;
import com.ljkj.blockpay.ui.adapter.CountryAdapter;
import com.ljkj.blockpay.widget.ClickListener;

import java.util.ArrayList;
import java.util.List;

public class SelectActivity extends BaseActivity<ActivitySelectBinding,SelectPresenter> implements SelectInter.SelectInterView, ClickListener {


    private CountryAdapter countryAdapter;
    @Override
    public int initContentView() {
        return R.layout.activity_select;
    }

    @Override
    protected SelectPresenter createPresenter() {
        return new SelectPresenter(this,this);
    }

    @Override
    protected void init(Bundle savedInstanceState) {

    }

    @Override
    protected void onStart() {
        super.onStart();
        getPresenter().CountryCode();
    }

    @Override
    protected void initData() {
        super.initData();
        binding.setOnClick(this::onClick);
        binding.tvTitle.setLeftBackFinish(this);
        binding.tvTitle.setTitleContent(R.string.selectcountry);
        getPresenter().CountryCode();

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.rvSelect.setLayoutManager(layoutManager);
        countryAdapter = new CountryAdapter(R.layout.selectcountry_layout);

        countryAdapter.setOnItemClickListener( (adapter, view, position) -> {
            Intent intent = getIntent();
            JsonList jsonList = (JsonList) adapter.getData();
            intent.putExtra("jsonMap",jsonList.getJsonMap(position).toString());
            setResult(100,intent);
            finish();
        });
    }


    @Override
    public void onClick(View view) {

    }

    @Override
    public void getCountryCode(List<CommonModel> commonModel) {
//
//        if (commonModel != null){
//            for (int i = 0; i < commonModel.size(); i++) {
//                countryAdapter.setNewData(commonModel);
//                Intent intent = getIntent();
//                intent.putExtra("")
//            }
//
//        }
    }

    @Override
    public void countryListSuccess(JsonList jsonMap) {
        countryAdapter.setNewData(jsonMap);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }
}